package vip.mengqin.diandezhun.ui.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.baselibrary.interface_.OkHttpCallBack;
import com.android.baselibrary.responce.BaseResponce;
import com.android.baselibrary.tool.CommLoading;
import com.android.baselibrary.tool.CommToast;
import com.android.baselibrary.view.Comm_HeadView;
import com.android.baselibrary.view.MultiStateView;

import org.w3c.dom.Text;

import butterknife.BindView;
import butterknife.OnClick;
import vip.mengqin.diandezhun.R;
import vip.mengqin.diandezhun.manager.API_Manager;
import vip.mengqin.diandezhun.responce.PayInfo_AliPayData;
import vip.mengqin.diandezhun.responce.PayInfo_PayResultData;

/**
 * 购买结果
 */
public class PayResultActivity extends BaseActivity {

    @BindView(R.id.multiplestatusView)
    MultiStateView multiplestatusView;
    @BindView(R.id.comm_title)
    Comm_HeadView comm_title;
    @BindView(R.id.iv_state)
    ImageView iv_state;
    @BindView(R.id.tv_state)
    TextView tv_state;


    int orderId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_pay_result;
    }

    @Override
    protected void initView() {
        comm_title.setTitle("订购结果");
        orderId = getIntent().getIntExtra("orderId", 0);
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        API_Manager.order_pay_result(mContext, orderId, new OkHttpCallBack<BaseResponce<PayInfo_PayResultData>>() {
            @Override
            public void onSuccess(BaseResponce<PayInfo_PayResultData> baseResponce) {
                PayInfo_PayResultData data = baseResponce.getData();
                //0：未支付 1：已支付  2：支付失败
                switch (data.payStatus) {
                    case 0:     //未支付
                    case 2:     //支付失败
                        tv_state.setText("支付失败");
                        iv_state.setImageResource(R.drawable.ico_pay_result_fail);
                        break;
                    case 1:     //已支付
                        tv_state.setText("支付成功");
                        iv_state.setImageResource(R.drawable.ico_pay_result_success);
                        break;
                }
            }

            @Override
            public void onFailure(BaseResponce<PayInfo_PayResultData> baseResponce) {
                CommToast.showToast(mContext, baseResponce.message);
            }
        });
    }

    @OnClick({R.id.tv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
        }
    }

}
